package com.golf.core.math.util;

/**
 * 
 * 
 * @author gfloodgate
 */
public abstract class VectorUtil 
{

	
	/**
	 * 
	 * = +/- acos ( a . b / |a| |b| )
	 * 
	 * NB: in radians !!!
	 * 
	 * @param a
	 * @param b
	 * @return
	 */
	public static final double angleBetweenTwoVectors(double vx1, double vy1, double vx2, double vy2)
	{
		double signMultiplier = 1;
		if ( (vx1 * vy2) - (vy1 * vx2) < 0)
		{
			signMultiplier = -1;
		}
		
		double vectorProduct = vectorProduct(vx1,vy1,vx2,vy2);
		double magnitudeProduct = vectorMagnitude(vx1,vy1) * vectorMagnitude(vx2,vy2);
		double angle =  signMultiplier * Math.acos( vectorProduct / magnitudeProduct );
		return angle;
	}
	
	
	/**
	 * a . b = a.x*b.x + a.y*b.y
	 * 
	 * @param a
	 * @param b
	 * @return
	 */
	public static final double vectorProduct(double vx1, double vy1, double vx2, double vy2)
	{
		return  ( vx1 * vx2 ) + ( vy1 * vy2 );
	}
	
	
	/**
	 * magnitude = |a| = sqrt ( a.x^2 + a.y^2 );
	 * 
	 * @param a
	 * @return
	 */
	public static final double vectorMagnitude(double vx, double vy)
	{
		return Math.sqrt(  Math.pow(vx, 2) + Math.pow(vy, 2) );
	}
	
}
